use egui_snarl::NodeId;
use serde::{Deserialize, Serialize};

use crate::graph::value::Value;

use super::{Input, NodeTrait, Output};


#[derive(Clone, Serialize, Deserialize)]
pub struct BlackboardInRefNode {
    pub ref_node: NodeId,
    pub value: Value,
    inputs: Vec<Input>,
    outputs: Vec<Output>,
}

impl BlackboardInRefNode {
    pub fn new(ref_node: NodeId, value: Value) -> Self {
        Self {
            ref_node,
            value: value.clone(),
            inputs: vec![],
            outputs: vec![Output {
                name: "Ref".to_string(),
                description: Some("引用黑板变量".to_string()),
                value: value,
            }],
        }
    }
}

impl NodeTrait for BlackboardInRefNode {
    fn name(&self) ->  &str {
        ""
    }

    fn ty(&self) ->  &str {
        "__BLACKBOARD_IN_REF_NODE__"
    }

    fn description(&self) -> Option<&str> {
        Some("黑板输入引用节点")
    }

    fn inputs(&self) ->  &[Input] {
        &self.inputs
    }

    fn outputs(&self) ->  &[Output] {
        &self.outputs
    }

    fn has_children(&self) -> bool {
        false
    }

    fn inputs_mut(&mut self) ->  &mut Vec<Input> {
        &mut self.inputs
    }

    fn outputs_mut(&mut self) ->  &mut Vec<Output> {
        &mut self.outputs
    }

    fn can_copy(&self) -> bool {
        false
    }
}
